package com.foreknow.view;

import com.foreknow.dao.AdminDao;
import com.foreknow.dao.GuestbookDao;
import com.foreknow.dao.inpl.AdminDaoImpl;
import com.foreknow.dao.inpl.GuestbookDaoImpl;
import com.foreknow.db.DBManager;
import com.foreknow.model.Admin;
import com.foreknow.model.Guestbook;
import com.foreknow.service.AdminService;
import com.foreknow.service.GuestbookService;
import com.foreknow.service.impl.AdminServiceImpl;
import com.foreknow.service.impl.GuestbookServiceImpl;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 测试数据库的链接
 */
public class TestDBManager {
    public static void main(String[] args) {
        //创建DBManager对象
        //静态方法调用
        //查询所有
//        DBManager dbManager= DBManager.getInstance();
//        dbManager.getConnection();
//        GuestbookDao guestbookDao = new GuestbookDaoImpl();
//        List<Object> list =guestbookDao.query();
//        for (int i = 0; i<list.size();i++){
//          Guestbook guestbook = (Guestbook) list.get(i);
//            System.out.println(guestbook.getId() + "    "+guestbook.getName()+"    "+guestbook.getPhone()+"   " +guestbook.getTitle());
//        }


        GuestbookService guestbookService = new GuestbookServiceImpl();
        Guestbook guestbook = new Guestbook();
        //添加
//        guestbook.setName("熊二");
//        guestbook.setPhone("121");
//        boolean isRight =guestbookService.save(guestbook);
//
//        if (isRight){
//            System.out.println("ok");
//
//        }else {
//            System.out.println("no");
//        }

     //删除
         boolean delete= guestbookService.delete(2);
                if (delete){
            System.out.println("ok");

        }else {
            System.out.println("no");
        }

        //修改
//        guestbook.setId(3);
//        guestbook.setName("2323");
//        guestbook.setPhone("1212");
//        boolean update=  guestbookService.update(guestbook);
//
//                if (update){
//            System.out.println("ok");
//
//        }else {
//            System.out.println("no");
//        }
            //根据id查询
//        Guestbook gg= guestbookService.Idquery(1);
//        System.out.println(gg.getId() + "    "+gg.getName()+"    "+gg.getPhone()+"   " +gg.getTitle()+"   "+gg.getEmail()+"   "+gg.getContent()+"   "+gg.getCreatetime());

        //修改方法
        guestbook.setId(3);
        guestbook.setName("111");
       boolean update = guestbookService.updates(guestbook);
            if (update){
            System.out.println("ok");

        }else {
            System.out.println("no");
        }

        Date date = new Date();
        //System.out.println(date);
        //需要将日期类型转换为字符串，然后添加到数据库中
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String new_date = simpleDateFormat.format(date);
        System.out.println(new_date);
    }
}
